<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="goods.*"%>
     <%@ page import="order.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="/Dmyna/admin/head.jsp" %>
<%
	String gs_code = request.getParameter("gs_code");
	GoodsManager goodsmanager = GoodsManager.getInstance();
	GoodsItem oldWriting = goodsmanager.select(gs_code);
	System.out.println(oldWriting);
	OrderManager ordermanager = OrderManager.getInstance();
	OrderItem orderItem = ordermanager.selectOrder(gs_code);
	System.out.println(orderItem);
%>

<c:set var="oldWriting" value="<%=oldWriting%>" />
<c:choose>
	<c:when test="${empty oldWriting }">
		<script>
			alert("상품이 존재하지 않습니다.");
			location.href = "${WEB_ROOT }/admin/goods/goodsList.jsp";
		</script>
	</c:when>
	<c:when test="${orderItem != null}">
		<script>
			alert("판매된 상품은 삭제할수 없습니다.");
			history.go(-1);
		</script>
	</c:when> 
	<c:otherwise>
		<% goodsmanager.delete(oldWriting.getGs_code()); %>
		<script>
			alert("상품이 삭제되었습니다");
			location.href = "${WEB_ROOT }/admin/goods/goodsList.jsp";
		</script>
	</c:otherwise>
</c:choose>

<%@ include file="/Dmyna/admin/tail.jsp" %>